package exception;

/**
 * java 异常处理机制：try...catch
 * try{
 *     代码片段
 * }catch(XXXException e){
 *     当try的代码片段出现XXXException时的补救措施
 * }
 */
public class TryCatchDemo {
    public static void main(String[] args) {
        System.out.println("开始");
        try {
            String line= null;
            System.out.println(line.length());
            String line1="";
            System.out.println(line1.charAt(0));
            String line2 = "abc";
            System.out.println(Integer.parseInt(line2));
        } catch (NullPointerException | StringIndexOutOfBoundsException e) {
            System.out.println("出现了空指针异常");
        }catch (Exception e){
            System.out.println("出现空指针或字符串下标越界异常并解决了");
        }
        System.out.println("结束");


    }
}